package com.zygh.policeasset.mapper;

import com.zygh.policeasset.pojo.NewApprovalProcess;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

@Mapper
public interface NewApprovalProcessMapper {
    @Insert({"insert into new_approval_process (build_num,section_id,approval_opinion,user_name,operating_time,approval_status,user_id) ", "values (#{buildNum},#{sectionId},#{approvalOpinion},#{userName},#{operatingTime},#{approvalStatus},#{userId})"})
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    int add(NewApprovalProcess newApprovalProcess);

    @Update({"<script>update new_approval_process set approval_opinion = #{approvalOpinion},operating_time = #{operatingTime},approval_status = #{approvalStatus} <where><if test='buildNum != null '>and  build_num = #{buildNum}  </if><if test='sectionId != null '>and  section_id = #{sectionId}  </if><if test='userId != null '>and  user_id = #{userId}  </if> </where>order by operating_time desc limit 1</script>"})
    int updateBycondtion(NewApprovalProcess newApprovalProcess);

    @Select({"<script>" +
            "select nap.*,a.approval_explain as approvalStatusName,u.name as userName " +
            "from new_approval_process nap " +
            "left join approval_status a on nap.approval_status = a.id " +
            "left join user u on nap.user_id = u.id " +
            "<where>" +
            "<if test='buildNum != null '>and  nap.build_num = #{buildNum}  </if>" +
            "<if test='sectionId != null '>and  nap.section_id = #{sectionId}  </if>" +
            " </where>" +
            "</script>"})
    @Results(id = "newApprovalProcessMap",
            value = {@Result(column = "build_num", property = "buildNum", jdbcType = JdbcType.INTEGER),
                    @Result(column = "section_id", property = "sectionId", jdbcType = JdbcType.VARCHAR),
                    @Result(column = "approval_opinion", property = "approvalOpinion", jdbcType = JdbcType.VARCHAR),
                    @Result(column = "operating_time", property = "operatingTime", jdbcType = JdbcType.VARCHAR),
                    @Result(column = "approval_status", property = "approvalStatus", jdbcType = JdbcType.VARCHAR),
                    @Result(column = "user_id", property = "userId", jdbcType = JdbcType.VARCHAR)})
    List<NewApprovalProcess> selectAllByBuildNum(@Param("buildNum") String buildNum,@Param("sectionId")  Integer sectionId);
}